package cn.tom.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter;

//资源服务器
@Configuration
@EnableResourceServer//放在过滤器链条
public class MyResourceServerConfig extends
        ResourceServerConfigurerAdapter {

    //资源
    @Override
    public void configure(HttpSecurity http) throws Exception {
        http.requestMatchers().antMatchers("/api/**")
                .and()
                .authorizeRequests()
                //.antMatchers("/api/adm/hot/findAll").permitAll()
                .antMatchers("/api/public/**").permitAll()  //放行公开权限
                .antMatchers("/api/adm/**").hasAuthority("G") //管理员的权限
                .anyRequest().authenticated();//剩下的全部要登录才能访问
    }
}
